package com.xsdl.singleton;

import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) throws InterruptedException {

        HIDGenerator hidGenerator = HIDGenerator.getInstance();
        Long nextId = hidGenerator.getNextId();
        System.out.println(nextId);
        nextId = hidGenerator.getNextId();
        System.out.println(nextId);

        LIDGenerator lidGenerator = LIDGenerator.getInstance();
        nextId = lidGenerator.getNextId();
        System.out.println(nextId);
        nextId = lidGenerator.getNextId();
        System.out.println(nextId);

        RIDGenerator ridGenerator = RIDGenerator.getInstance();
        nextId = ridGenerator.getNextId();
        System.out.println(nextId);
        nextId = ridGenerator.getNextId();
        System.out.println(nextId);

        IDGenerator instance = IDGenerator.getInstance();
        nextId = instance.getNextId();
        System.out.println(nextId);
        nextId = instance.getNextId();
        System.out.println(nextId);

        IntStream.rangeClosed(1, 10).parallel().forEach(i -> {
            Thread thread = new Thread(() -> {
                MIDGenerator temp = MIDGenerator.getInstance();
                System.out.println(Thread.currentThread().getName() + ":" + temp.getNextId());
            });
            thread.setName(String.valueOf(i));
            thread.start();
        });

        Thread.sleep(2000);

        System.out.println("======================");

        IntStream.rangeClosed(1, 10).parallel().forEach(i -> {
            Thread thread = new Thread(() -> {
                IDGenerator temp = IDGenerator.getInstance();
                System.out.println(Thread.currentThread().getName() + ":" + temp.getNextId());
            });
            thread.setName(String.valueOf(i));
            thread.start();
        });
        Thread.sleep(2000);

    }

}
